package com.libc.yygh.hosp.core.config;

import com.libc.yygh.hosp.core.filter.MyAppFilter;
import com.libc.yygh.hosp.core.listener.MyAppListener;
import com.libc.yygh.hosp.core.servlet.MyAppServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * *
 * Created with Description:
 *
 * @fileRelativePath: MyServiceConfig.java
 * @Date: Created on 2022/4/12  16:00  <br>
 * @author: LiBencheng <br>
 * @version: 1.0 <br>
 */
@Configuration
public class MyServiceConfig
{
    @Bean
    public ServletListenerRegistrationBean< MyAppListener > regMyListener( )
    {

        System.err.println("MyServiceConfig...注册...ServletListenerRegistrationBean...");

        ServletListenerRegistrationBean< MyAppListener > registrationBean =
                new ServletListenerRegistrationBean< MyAppListener >(new MyAppListener());
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean< MyAppFilter > regMyFilter( )
    {
        System.err.println("MyServiceConfig...注册...FilterRegistrationBean...");

        FilterRegistrationBean< MyAppFilter > registrationBean = new FilterRegistrationBean< MyAppFilter >();
        registrationBean.setFilter(new MyAppFilter());
        // 請求地址
        registrationBean.setUrlPatterns(Arrays.asList("/FoodServlet", "/food"));

        return registrationBean;
    }

    @Bean
    public ServletRegistrationBean< MyAppServlet > regMyServlet( )
    {
        System.err.println("MyServiceConfig...注册...ServletRegistrationBean...");

        ServletRegistrationBean< MyAppServlet > servletRegistrationBean =
                new ServletRegistrationBean< MyAppServlet >(new MyAppServlet(), "/MyServlet");

        return servletRegistrationBean;
    }

}
